<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Linux常用命令 | 邢昊波的个人笔记</title>
    <meta name="generator" content="VuePress 1.8.2">
    <link rel="icon" href="/favicon.ico">
    <meta name="description" content="记录生活，记录点滴">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
    
    <link rel="preload" href="/assets/css/0.styles.d32511b8.css" as="style"><link rel="preload" href="/assets/js/app.44c52f9e.js" as="script"><link rel="preload" href="/assets/js/3.60b348b7.js" as="script"><link rel="preload" href="/assets/js/1.576b739e.js" as="script"><link rel="preload" href="/assets/js/11.7184074e.js" as="script"><link rel="prefetch" href="/assets/js/10.36119258.js"><link rel="prefetch" href="/assets/js/12.3e7b79bc.js"><link rel="prefetch" href="/assets/js/13.35e27885.js"><link rel="prefetch" href="/assets/js/14.60e16f38.js"><link rel="prefetch" href="/assets/js/15.6cd1409a.js"><link rel="prefetch" href="/assets/js/16.b70ca709.js"><link rel="prefetch" href="/assets/js/4.00518278.js"><link rel="prefetch" href="/assets/js/5.ecf37b4b.js"><link rel="prefetch" href="/assets/js/6.fa756a2e.js"><link rel="prefetch" href="/assets/js/7.b13a6b81.js"><link rel="prefetch" href="/assets/js/8.93d9d6ae.js"><link rel="prefetch" href="/assets/js/9.87fd42a4.js">
    <link rel="stylesheet" href="/assets/css/0.styles.d32511b8.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container" data-v-1aefc0b4><div data-v-1aefc0b4><div id="loader-wrapper" class="loading-wrapper" data-v-d48f4d20 data-v-1aefc0b4 data-v-1aefc0b4><div class="loader-main" data-v-d48f4d20><div data-v-d48f4d20></div><div data-v-d48f4d20></div><div data-v-d48f4d20></div><div data-v-d48f4d20></div></div> <!----> <!----></div> <div class="password-shadow password-wrapper-out" style="display:none;" data-v-25ba6db2 data-v-1aefc0b4 data-v-1aefc0b4><h3 class="title" data-v-25ba6db2 data-v-25ba6db2>邢昊波的个人笔记</h3> <p class="description" data-v-25ba6db2 data-v-25ba6db2>记录生活，记录点滴</p> <label id="box" class="inputBox" data-v-25ba6db2 data-v-25ba6db2><input type="password" value="" data-v-25ba6db2> <span data-v-25ba6db2>Konck! Knock!</span> <button data-v-25ba6db2>OK</button></label> <div class="footer" data-v-25ba6db2 data-v-25ba6db2><span data-v-25ba6db2><i class="iconfont reco-theme" data-v-25ba6db2></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-25ba6db2>vuePress-theme-reco</a></span> <span data-v-25ba6db2><i class="iconfont reco-copyright" data-v-25ba6db2></i> <a data-v-25ba6db2><span data-v-25ba6db2>xinghb</span>
            
          <span data-v-25ba6db2>2021-2022 - </span>
          2022
        </a></span></div></div> <div class="hide" data-v-1aefc0b4><header class="navbar" data-v-1aefc0b4><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="/logo.png" alt="邢昊波的个人笔记" class="logo"> <span class="site-name">邢昊波的个人笔记</span></a> <div class="links"><div class="color-picker"><a class="color-button"><i class="iconfont reco-color"></i></a> <div class="color-picker-menu" style="display:none;"><div class="mode-options"><h4 class="title">Choose mode</h4> <ul class="color-mode-options"><li class="dark">dark</li><li class="auto active">auto</li><li class="light">light</li></ul></div></div></div> <div class="search-box"><i class="iconfont reco-search"></i> <input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/" class="nav-link"><i class="iconfont reco-home"></i>
  首页
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      服务部署
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/docs/linux/" aria-current="page" class="nav-link router-link-exact-active router-link-active"><i class="undefined"></i>
  Linux相关
</a></li><li class="dropdown-item"><!----> <a href="/docs/docker/" class="nav-link"><i class="undefined"></i>
  Docker相关
</a></li></ul></div></div><div class="nav-item"><a href="/timeline/" class="nav-link"><i class="iconfont reco-date"></i>
  归档
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      联系
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://github.com/devinbo" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-github"></i>
  GitHub
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div> <!----></nav></div></header> <div class="sidebar-mask" data-v-1aefc0b4></div> <aside class="sidebar" data-v-1aefc0b4><div class="personal-info-wrapper" data-v-39576ba9 data-v-1aefc0b4><img src="/avatar.png" alt="author-avatar" class="personal-img" data-v-39576ba9> <h3 class="name" data-v-39576ba9>
    xinghb
  </h3> <div class="num" data-v-39576ba9><div data-v-39576ba9><h3 data-v-39576ba9>6</h3> <h6 data-v-39576ba9>Articles</h6></div> <div data-v-39576ba9><h3 data-v-39576ba9>3</h3> <h6 data-v-39576ba9>Tags</h6></div></div> <ul class="social-links" data-v-39576ba9></ul> <hr data-v-39576ba9></div> <nav class="nav-links"><div class="nav-item"><a href="/" class="nav-link"><i class="iconfont reco-home"></i>
  首页
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      服务部署
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/docs/linux/" aria-current="page" class="nav-link router-link-exact-active router-link-active"><i class="undefined"></i>
  Linux相关
</a></li><li class="dropdown-item"><!----> <a href="/docs/docker/" class="nav-link"><i class="undefined"></i>
  Docker相关
</a></li></ul></div></div><div class="nav-item"><a href="/timeline/" class="nav-link"><i class="iconfont reco-date"></i>
  归档
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      联系
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://github.com/devinbo" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-github"></i>
  GitHub
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div> <!----></nav> <ul class="sidebar-links"><li><a href="/docs/linux/" aria-current="page" class="active sidebar-link">Linux常用命令</a></li></ul> </aside> <div class="password-shadow password-wrapper-in" style="display:none;" data-v-25ba6db2 data-v-1aefc0b4><h3 class="title" data-v-25ba6db2 data-v-25ba6db2>Linux常用命令</h3> <!----> <label id="box" class="inputBox" data-v-25ba6db2 data-v-25ba6db2><input type="password" value="" data-v-25ba6db2> <span data-v-25ba6db2>Konck! Knock!</span> <button data-v-25ba6db2>OK</button></label> <div class="footer" data-v-25ba6db2 data-v-25ba6db2><span data-v-25ba6db2><i class="iconfont reco-theme" data-v-25ba6db2></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-25ba6db2>vuePress-theme-reco</a></span> <span data-v-25ba6db2><i class="iconfont reco-copyright" data-v-25ba6db2></i> <a data-v-25ba6db2><span data-v-25ba6db2>xinghb</span>
            
          <span data-v-25ba6db2>2021-2022 - </span>
          2022
        </a></span></div></div> <div data-v-1aefc0b4><main class="page"><section><div class="page-title"><h1 class="title">Linux常用命令</h1> <div data-v-f875f3fc><i class="iconfont reco-account" data-v-f875f3fc><span data-v-f875f3fc>xinghb</span></i> <i class="iconfont reco-date" data-v-f875f3fc><span data-v-f875f3fc>1/23/2022</span></i> <!----> <i class="tags iconfont reco-tag" data-v-f875f3fc><span class="tag-item" data-v-f875f3fc>linux</span></i></div></div> <div class="theme-reco-content content__default"><div class="custom-block tip"><p class="title"></p><p>平时经常使用的linux命令，基于centos7.6</p></div><h2 id="系统服务管理"><a href="#系统服务管理" class="header-anchor">#</a> 系统服务管理</h2> <h3 id="systemctl"><a href="#systemctl" class="header-anchor">#</a> systemctl</h3> <ul><li>输出个服务状态</li></ul> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>systemctl list-units --type<span class="token operator">=</span>service
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>查看服务的运行状态</li></ul> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>systemctl status firewalld
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>关闭服务</li></ul> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>systemctl stop firewalld
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>启动服务</li></ul> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>systemctl start firewalld
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>重新启动服务（不管当前服务是启动还是关闭）</li></ul> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>systemctl restart firewalld
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>重新载入配置信息而不中断服务</li></ul> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>systemctl reload firewalld
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>禁止服务开机自启动</li></ul> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>systemctl disable firewalld
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>设置服务开机自启动：</li></ul> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>systemctl <span class="token builtin class-name">enable</span> firewalld
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h2 id="文件管理"><a href="#文件管理" class="header-anchor">#</a> 文件管理</h2> <h3 id="ls"><a href="#ls" class="header-anchor">#</a> ls</h3> <p>列出当前目录(/)下的所有文件</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">ls</span> -l /
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="pwd"><a href="#pwd" class="header-anchor">#</a> pwd</h3> <p>获取目前所在工作目录的绝对路径</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">ls</span> -l /
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><img src="" alt="refer_screen_08"></p> <h3 id="cd"><a href="#cd" class="header-anchor">#</a> cd</h3> <p>改变当前工作目录</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token builtin class-name">cd</span> /usr/local
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="date"><a href="#date" class="header-anchor">#</a> date</h3> <p>显示或修改系统时间与日期</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">date</span> <span class="token string">'+%Y-%m-%d %H:%M:%S'</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="password"><a href="#password" class="header-anchor">#</a> password</h3> <p>用于设置用户密码</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">passwd</span> root
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="su"><a href="#su" class="header-anchor">#</a> su</h3> <p>改变用户身份（切换到超级用户）</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">su</span> -
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="clear"><a href="#clear" class="header-anchor">#</a> clear</h3> <p>用于清除屏幕信息</p> <h3 id="man"><a href="#man" class="header-anchor">#</a> man</h3> <p>显示指定命令的帮助信息：</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">man</span> <span class="token function">ls</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="who"><a href="#who" class="header-anchor">#</a> who</h3> <ul><li>查询系统处于什么运行级别</li></ul> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">who</span> -r
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>显示目前登录到系统的用户</li></ul> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">who</span> -buT
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="free"><a href="#free" class="header-anchor">#</a> free</h3> <p>显示系统内存状态（单位MB）：</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">free</span> -m
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="ps"><a href="#ps" class="header-anchor">#</a> ps</h3> <ul><li>显示系统进程运行动态</li></ul> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">ps</span> -ef
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>查看sshd进程的运行动态</li></ul> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">ps</span> -ef <span class="token operator">|</span> <span class="token function">grep</span> sshd
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="top"><a href="#top" class="header-anchor">#</a> top</h3> <p>查看即时活跃的进程，类似Windows的任务管理器</p> <h3 id="mkdir"><a href="#mkdir" class="header-anchor">#</a> mkdir</h3> <p>创建目录</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">mkdir</span> mydata
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="more"><a href="#more" class="header-anchor">#</a> more</h3> <p>用于分页查看文件，例如每页10行查看<code>boot.log</code>文件</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">more</span> -c -10 /var/log/boot.log
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="cat"><a href="#cat" class="header-anchor">#</a> cat</h3> <p>用于查看文件，例如查看Linux启动日志文件文件，并标明行号</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">cat</span> -Ab /var/log/boot.log
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="touch"><a href="#touch" class="header-anchor">#</a> touch</h3> <p>用于创建文件，例如创建<code>text.txt</code>文件</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">touch</span> text.txt
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="rm"><a href="#rm" class="header-anchor">#</a> rm</h3> <ul><li>删除文件</li></ul> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">rm</span> text.txt
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>强制删除某个目录及其子目录</li></ul> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">rm</span> -rf testdir/
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="cp"><a href="#cp" class="header-anchor">#</a> cp</h3> <p>用于拷贝文件，例如将<code>test1</code>目录复制到<code>test2</code>目录</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">cp</span> -r /mydata/tes1 /mydata/test2
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="mv"><a href="#mv" class="header-anchor">#</a> mv</h3> <p>用于移动或覆盖文件</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">mv</span> text.txt text2.txt
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h4 id=""><a href="#" class="header-anchor">#</a></h4> <h2 id="压缩与解压"><a href="#压缩与解压" class="header-anchor">#</a> 压缩与解压</h2> <h3 id="tar"><a href="#tar" class="header-anchor">#</a> tar</h3> <ul><li>将<code>/etc</code>文件夹中的文件归档到文件<code>etc.tar</code>（并不会进行压缩）</li></ul> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">tar</span> -cvf /mydata/etc.tar /etc
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>用<code>gzip</code>压缩文件夹<code>/etc</code>中的文件到文件<code>etc.tar.gz</code></li></ul> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">tar</span> -zcvf /mydata/etc.tar.gz /etc
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>用<code>bzip2</code>压缩文件夹<code>/etc</code>到文件<code>/etc.tar.bz2</code></li></ul> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">tar</span> -jcvf /mydata/etc.tar.bz2 /etc
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>分页查看压缩包中内容（gzip）</li></ul> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">tar</span> -ztvf /mydata/etc.tar.gz <span class="token operator">|</span><span class="token function">more</span> -c -10
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>解压文件到当前目录（gzip）</li></ul> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">tar</span> -zxvf /mydata/etc.tar.gz
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>解压文件到指定目录（gzip）</li></ul> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">tar</span> -zxvf /mydata/etc.tar.gz -C /mydata/etc
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h2 id="磁盘和网络管理"><a href="#磁盘和网络管理" class="header-anchor">#</a> 磁盘和网络管理</h2> <h3 id="df"><a href="#df" class="header-anchor">#</a> df</h3> <p>查看磁盘空间占用情况</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">df</span> -hT
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="dh"><a href="#dh" class="header-anchor">#</a> dh</h3> <p>查看当前目录下的文件及文件夹所占大小</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">du</span> -h --max-depth<span class="token operator">=</span><span class="token number">1</span> ./*
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="ifconfig"><a href="#ifconfig" class="header-anchor">#</a> ifconfig</h3> <p>显示当前网络接口状态</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">ifconfig</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="netstat"><a href="#netstat" class="header-anchor">#</a> netstat</h3> <ul><li>查看当前路由信息</li></ul> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">netstat</span> -rn
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>查看所有有效TCP连接</li></ul> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">netstat</span> -an
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>查看系统中启动的监听服务</li></ul> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">netstat</span> -tulnp
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>查看处于连接状态的系统资源信息：</li></ul> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">netstat</span> -atunp
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="wget"><a href="#wget" class="header-anchor">#</a> wget</h3> <p>从网络上下载文件</p> <h2 id="文件上传下载"><a href="#文件上传下载" class="header-anchor">#</a> 文件上传下载</h2> <ul><li>安装上传下载工具<code>lrzsz</code>；</li></ul> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>yum <span class="token function">install</span> -y lrzsz
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>上传文件，输入以下命令<code>XShell</code>会弹出文件上传框；</li></ul> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>rz
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>下载文件，输入以下命令<code>XShell</code>会弹出文件保存框；</li></ul> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>sz fileName
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h2 id="软件的安装和管理"><a href="#软件的安装和管理" class="header-anchor">#</a> 软件的安装和管理</h2> <h3 id="rpm"><a href="#rpm" class="header-anchor">#</a> rpm</h3> <div class="custom-block tip"><p class="title"></p><p>RPM是<code>Red-Hat Package Manager</code>的缩写，一种Linux下通用的软件包管理方式，可用于安装和管理<code>.rpm</code>结尾的软件包。</p></div><ul><li>安装软件包：</li></ul> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">rpm</span> -ivh nginx-1.12.2-2.el7.x86_64.rpm
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>模糊搜索软件包：</li></ul> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token function">rpm</span> -qa <span class="token operator">|</span> <span class="token function">grep</span> nginxCopy to clipboardErrorCopied
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>精确查找软件包：</li></ul> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token function">rpm</span> -qa nginxCopy to clipboardErrorCopied
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>查询软件包的安装路径：</li></ul> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token function">rpm</span> -ql nginx-1.12.2-2.el7.x86_64Copy to clipboardErrorCopied
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>查看软件包的概要信息：</li></ul> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token function">rpm</span> -qi nginx-1.12.2-2.el7.x86_64Copy to clipboardErrorCopied
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>验证软件包内容和安装文件是否一致：</li></ul> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token function">rpm</span> -V nginx-1.12.2-2.el7.x86_64Copy to clipboardErrorCopied
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>更新软件包：</li></ul> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token function">rpm</span> -Uvh nginx-1.12.2-2.el7.x86_64Copy to clipboardErrorCopied
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>删除软件包：</li></ul> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token function">rpm</span> -e nginx-1.12.2-2.el7.x86_64
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h2 id="yum"><a href="#yum" class="header-anchor">#</a> yum</h2> <div class="custom-block tip"><p class="title"></p><p>Yum是<code>Yellow dog Updater, Modified</code>的缩写，能够在线自动下载RPM包并安装，可以自动处理依赖性关系，并且一次安装所有依赖的软件包，非常方便！</p></div><ul><li>安装软件包：</li></ul> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>yum <span class="token function">install</span> nginxCopy to clipboardErrorCopied
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>检查可以更新的软件包：</li></ul> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>yum check-updateCopy to clipboardErrorCopied
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>更新指定的软件包：</li></ul> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>yum update nginxCopy to clipboardErrorCopied
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>在资源库中查找软件包信息：</li></ul> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>yum info nginx*Copy to clipboardErrorCopied
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>列出已经安装的所有软件包：</li></ul> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>yum info installedCopy to clipboardErrorCopied
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>列出软件包名称：</li></ul> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>yum list nginx*Copy to clipboardErrorCopied
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>模糊搜索软件包：</li></ul> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>yum search nginx
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h2 id="用户管理"><a href="#用户管理" class="header-anchor">#</a> 用户管理</h2> <ul><li>查看用户信息：</li></ul> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token function">cat</span> /etc/passwdCopy to clipboardErrorCopied
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>用户信息格式如下（密码已过滤）：</li></ul> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token comment"># 用户名:密码:用户标识号:组标识号:组注释性描述:主目录:默认shell</span>
root:x:0:0:root:/root:/bin/bash
macro:x:1000:982:macro:/home/macro:/bin/bashCopy to clipboardErrorCopied
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><ul><li>查看用户组信息：</li></ul> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token function">cat</span> /etc/groupCopy to clipboardErrorCopied
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>用户组信息格式如下：</li></ul> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token comment"># 组名:密码:组标识号:组内用户列表</span>
root:x:0:
docker:x:982:macro,andyCopy to clipboardErrorCopied
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><h3 id="passwd"><a href="#passwd" class="header-anchor">#</a> passwd</h3> <p>用于设置用户密码：</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token function">passwd</span> rootCopy to clipboardErrorCopied
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="su-2"><a href="#su-2" class="header-anchor">#</a> su</h3> <p>改变用户身份（切换到超级用户）：</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token comment"># 切换到root用户</span>
<span class="token function">su</span> -
<span class="token comment"># 切换到macro用户</span>
<span class="token function">su</span> macroCopy to clipboardErrorCopied
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><h3 id="groupadd"><a href="#groupadd" class="header-anchor">#</a> groupadd</h3> <p>添加用户组，使用<code>-g</code>可以设置用户组的标志号：</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token function">groupadd</span> -g <span class="token number">1024</span> macrozhengCopy to clipboardErrorCopied
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="groupdel"><a href="#groupdel" class="header-anchor">#</a> groupdel</h3> <p>删除用户组：</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token function">groupdel</span> macrozhengCopy to clipboardErrorCopied
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="useradd"><a href="#useradd" class="header-anchor">#</a> useradd</h3> <p>添加用户，<code>-u</code>设置标志号，<code>-g</code>设置主用户组：</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token function">useradd</span> -u <span class="token number">1024</span> -g macrozheng macroCopy to clipboardErrorCopied
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="usermod"><a href="#usermod" class="header-anchor">#</a> usermod</h3> <p>修改用户所属用户组：</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token function">usermod</span> -g <span class="token function">docker</span> macroCopy to clipboardErrorCopied
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="userdel"><a href="#userdel" class="header-anchor">#</a> userdel</h3> <p>删除用户，使用<code>-r</code>可以删除用户主目录：</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token function">userdel</span> macro -r
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div></div></section> <footer class="page-edit"><!----> <!----></footer> <!----> <div class="comments-wrapper"><!----></div> <ul class="side-bar sub-sidebar-wrapper" style="width:12rem;" data-v-cb1513f6><li class="level-2" data-v-cb1513f6><a href="/docs/linux/#系统服务管理" class="sidebar-link reco-side-系统服务管理" data-v-cb1513f6>系统服务管理</a></li><li class="level-3" data-v-cb1513f6><a href="/docs/linux/#systemctl" class="sidebar-link reco-side-systemctl" data-v-cb1513f6>systemctl</a></li><li class="level-2" data-v-cb1513f6><a href="/docs/linux/#文件管理" class="sidebar-link reco-side-文件管理" data-v-cb1513f6>文件管理</a></li><li class="level-3" data-v-cb1513f6><a href="/docs/linux/#ls" class="sidebar-link reco-side-ls" data-v-cb1513f6>ls</a></li><li class="level-3" data-v-cb1513f6><a href="/docs/linux/#pwd" class="sidebar-link reco-side-pwd" data-v-cb1513f6>pwd</a></li><li class="level-3" data-v-cb1513f6><a href="/docs/linux/#cd" class="sidebar-link reco-side-cd" data-v-cb1513f6>cd</a></li><li class="level-3" data-v-cb1513f6><a href="/docs/linux/#date" class="sidebar-link reco-side-date" data-v-cb1513f6>date</a></li><li class="level-3" data-v-cb1513f6><a href="/docs/linux/#password" class="sidebar-link reco-side-password" data-v-cb1513f6>password</a></li><li class="level-3" data-v-cb1513f6><a href="/docs/linux/#su" class="sidebar-link reco-side-su" data-v-cb1513f6>su</a></li><li class="level-3" data-v-cb1513f6><a href="/docs/linux/#clear" class="sidebar-link reco-side-clear" data-v-cb1513f6>clear</a></li><li class="level-3" data-v-cb1513f6><a href="/docs/linux/#man" class="sidebar-link reco-side-man" data-v-cb1513f6>man</a></li><li class="level-3" data-v-cb1513f6><a href="/docs/linux/#who" class="sidebar-link reco-side-who" data-v-cb1513f6>who</a></li><li class="level-3" data-v-cb1513f6><a href="/docs/linux/#free" class="sidebar-link reco-side-free" data-v-cb1513f6>free</a></li><li class="level-3" data-v-cb1513f6><a href="/docs/linux/#ps" class="sidebar-link reco-side-ps" data-v-cb1513f6>ps</a></li><li class="level-3" data-v-cb1513f6><a href="/docs/linux/#top" class="sidebar-link reco-side-top" data-v-cb1513f6>top</a></li><li class="level-3" data-v-cb1513f6><a href="/docs/linux/#mkdir" class="sidebar-link reco-side-mkdir" data-v-cb1513f6>mkdir</a></li><li class="level-3" data-v-cb1513f6><a href="/docs/linux/#more" class="sidebar-link reco-side-more" data-v-cb1513f6>more</a></li><li class="level-3" data-v-cb1513f6><a href="/docs/linux/#cat" class="sidebar-link reco-side-cat" data-v-cb1513f6>cat</a></li><li class="level-3" data-v-cb1513f6><a href="/docs/linux/#touch" class="sidebar-link reco-side-touch" data-v-cb1513f6>touch</a></li><li class="level-3" data-v-cb1513f6><a href="/docs/linux/#rm" class="sidebar-link reco-side-rm" data-v-cb1513f6>rm</a></li><li class="level-3" data-v-cb1513f6><a href="/docs/linux/#cp" class="sidebar-link reco-side-cp" data-v-cb1513f6>cp</a></li><li class="level-3" data-v-cb1513f6><a href="/docs/linux/#mv" class="sidebar-link reco-side-mv" data-v-cb1513f6>mv</a></li><li class="level-2" data-v-cb1513f6><a href="/docs/linux/#压缩与解压" class="sidebar-link reco-side-压缩与解压" data-v-cb1513f6>压缩与解压</a></li><li class="level-3" data-v-cb1513f6><a href="/docs/linux/#tar" class="sidebar-link reco-side-tar" data-v-cb1513f6>tar</a></li><li class="level-2" data-v-cb1513f6><a href="/docs/linux/#磁盘和网络管理" class="sidebar-link reco-side-磁盘和网络管理" data-v-cb1513f6>磁盘和网络管理</a></li><li class="level-3" data-v-cb1513f6><a href="/docs/linux/#df" class="sidebar-link reco-side-df" data-v-cb1513f6>df</a></li><li class="level-3" data-v-cb1513f6><a href="/docs/linux/#dh" class="sidebar-link reco-side-dh" data-v-cb1513f6>dh</a></li><li class="level-3" data-v-cb1513f6><a href="/docs/linux/#ifconfig" class="sidebar-link reco-side-ifconfig" data-v-cb1513f6>ifconfig</a></li><li class="level-3" data-v-cb1513f6><a href="/docs/linux/#netstat" class="sidebar-link reco-side-netstat" data-v-cb1513f6>netstat</a></li><li class="level-3" data-v-cb1513f6><a href="/docs/linux/#wget" class="sidebar-link reco-side-wget" data-v-cb1513f6>wget</a></li><li class="level-2" data-v-cb1513f6><a href="/docs/linux/#文件上传下载" class="sidebar-link reco-side-文件上传下载" data-v-cb1513f6>文件上传下载</a></li><li class="level-2" data-v-cb1513f6><a href="/docs/linux/#软件的安装和管理" class="sidebar-link reco-side-软件的安装和管理" data-v-cb1513f6>软件的安装和管理</a></li><li class="level-3" data-v-cb1513f6><a href="/docs/linux/#rpm" class="sidebar-link reco-side-rpm" data-v-cb1513f6>rpm</a></li><li class="level-2" data-v-cb1513f6><a href="/docs/linux/#yum" class="sidebar-link reco-side-yum" data-v-cb1513f6>yum</a></li><li class="level-2" data-v-cb1513f6><a href="/docs/linux/#用户管理" class="sidebar-link reco-side-用户管理" data-v-cb1513f6>用户管理</a></li><li class="level-3" data-v-cb1513f6><a href="/docs/linux/#passwd" class="sidebar-link reco-side-passwd" data-v-cb1513f6>passwd</a></li><li class="level-3" data-v-cb1513f6><a href="/docs/linux/#su-2" class="sidebar-link reco-side-su-2" data-v-cb1513f6>su</a></li><li class="level-3" data-v-cb1513f6><a href="/docs/linux/#groupadd" class="sidebar-link reco-side-groupadd" data-v-cb1513f6>groupadd</a></li><li class="level-3" data-v-cb1513f6><a href="/docs/linux/#groupdel" class="sidebar-link reco-side-groupdel" data-v-cb1513f6>groupdel</a></li><li class="level-3" data-v-cb1513f6><a href="/docs/linux/#useradd" class="sidebar-link reco-side-useradd" data-v-cb1513f6>useradd</a></li><li class="level-3" data-v-cb1513f6><a href="/docs/linux/#usermod" class="sidebar-link reco-side-usermod" data-v-cb1513f6>usermod</a></li><li class="level-3" data-v-cb1513f6><a href="/docs/linux/#userdel" class="sidebar-link reco-side-userdel" data-v-cb1513f6>userdel</a></li></ul></main> <!----></div></div></div></div><div class="global-ui"><div class="back-to-ceiling" style="right:1rem;bottom:6rem;width:2.5rem;height:2.5rem;border-radius:.25rem;line-height:2.5rem;display:none;" data-v-c6073ba8 data-v-c6073ba8><svg t="1574745035067" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5404" class="icon" data-v-c6073ba8><path d="M526.60727968 10.90185116a27.675 27.675 0 0 0-29.21455937 0c-131.36607665 82.28402758-218.69155461 228.01873535-218.69155402 394.07834331a462.20625001 462.20625001 0 0 0 5.36959153 69.94390903c1.00431239 6.55289093-0.34802892 13.13561351-3.76865779 18.80351572-32.63518765 54.11355614-51.75690182 118.55860487-51.7569018 187.94566865a371.06718723 371.06718723 0 0 0 11.50484808 91.98906777c6.53300375 25.50556257 41.68394495 28.14064038 52.69160883 4.22606766 17.37162448-37.73630017 42.14135425-72.50938081 72.80769204-103.21549295 2.18761121 3.04276886 4.15646224 6.24463696 6.40373557 9.22774369a1871.4375 1871.4375 0 0 0 140.04691725 5.34970492 1866.36093723 1866.36093723 0 0 0 140.04691723-5.34970492c2.24727335-2.98310674 4.21612437-6.18497483 6.3937923-9.2178004 30.66633723 30.70611158 55.4360664 65.4791928 72.80769147 103.21549355 11.00766384 23.91457269 46.15860503 21.27949489 52.69160879-4.22606768a371.15156223 371.15156223 0 0 0 11.514792-91.99901164c0-69.36717486-19.13165746-133.82216804-51.75690182-187.92578088-3.42062944-5.66790279-4.76302748-12.26056868-3.76865837-18.80351632a462.20625001 462.20625001 0 0 0 5.36959269-69.943909c-0.00994388-166.08943902-87.32547796-311.81420293-218.6915546-394.09823051zM605.93803103 357.87693858a93.93749974 93.93749974 0 1 1-187.89594924 6.1e-7 93.93749974 93.93749974 0 0 1 187.89594924-6.1e-7z" p-id="5405" data-v-c6073ba8></path><path d="M429.50777625 765.63860547C429.50777625 803.39355007 466.44236686 1000.39046097 512.00932183 1000.39046097c45.56695499 0 82.4922232-197.00623328 82.5015456-234.7518555 0-37.75494459-36.9345906-68.35043303-82.4922232-68.34111062-45.57627738-0.00932239-82.52019037 30.59548842-82.51086798 68.34111062z" p-id="5406" data-v-c6073ba8></path></svg></div></div></div>
    <script src="/assets/js/app.44c52f9e.js" defer></script><script src="/assets/js/3.60b348b7.js" defer></script><script src="/assets/js/1.576b739e.js" defer></script><script src="/assets/js/11.7184074e.js" defer></script>
  </body>
</html>
